package com.jeesite.modules;

import com.jeesite.common.lang.DateUtils;
import com.jeesite.modules.fty.entity.FtySelContract;
import com.jeesite.modules.sys.utils.DictUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * Created by chensk on 2018/5/24.
 */
public class ReplaceUtils {




    public static String replaceHd(String contract, FtySelContract ftySelContract) {
        String s1 = "合同签定之日，乙方支付购房定金<span class=\"underline\" style=\"width:110px;\">#h_money_first#</span>元整，给甲方，此定金可抵扣房款。|";
        String s2 = "在<span class=\"underline\" style=\"width:45px;\">#h_time_second#</span>日内，首付房款<span class=\'underline\' style=\'width:110px;\'>#h_money_second#</span>元整，在丙方的见证下由乙方支付给甲方#use_hd#|";
        String s3 = "房款<span class=\"underline\" style=\"width:110px;\">#h_money_third#</span>元整，在<span class=\"underline\" style=\"width:45px;\">#h_time_third#</span>日在丙方的见证下由乙方支付给甲方;|";
        String s4 = "余款<span class=\"underline\" style=\"width:110px;\">#h_money_four#</span>元整，在<span class=\"underline\" style=\"width:45px;\">#h_time_four#</span>日在丙方的见证下由乙方支付给甲方;|";
        String s5 = "余款<span class=\"underline\" style=\"width:110px;\">#h_money_five#</span>元整，乙方委托丙方办理（#dk_fs#）银行按揭手续，待乙方三证及它项权证办妥后由银行直接付给甲方。实际贷款年限按银行规定。|";
        String s6 = "卖买双方产权过户日期约定：按存量房中介合同上约定由丙方组织于<span class=\"underline\" style=\"width:45px;\">#h_time_five#</span>前，（注：国家正常工作日）到出售房屋所在地交易中心，办理产权过户手续，交易契税交付后，当天在丙方见证下由乙方支付给甲方按合同上要求约定的全部首付款。";

        String sargs ="";
        if("".equals(ftySelContract.getHMoneyThird())||"0".equals(ftySelContract.getHMoneyThird())||null==ftySelContract.getHMoneyThird()){
            s3 = "";

        }

        if("".equals(ftySelContract.getHMoneyFour())||"0".equals(ftySelContract.getHMoneyFour())||null==ftySelContract.getHMoneyFour()){

            s4 ="";
        }

        if("".equals(ftySelContract.getHMoneyFive())||"0".equals(ftySelContract.getHMoneyFive())||null==ftySelContract.getHMoneyFive()){
            s5="";

        }
        StringBuffer bs = new StringBuffer();

        sargs = "1、"+s1+s2+s3+s4+s5+s6;
        int count = 1 ;
        for(int i=0;i<sargs.length();i++){
            if(sargs.charAt(i) == '|'){
                count++;
                bs.append("<br />"+count+"、");
            }else{
                bs.append(sargs.charAt(i));
            }
        }

        sargs = bs.toString();

        if(ftySelContract.getUseHd().equals("是")){
            sargs  = sargs.replaceAll("\\#use_hd\\#", ",用于甲方还贷。");
        }
        if(ftySelContract.getUseHd().equals("否")){
            sargs  = sargs.replaceAll("\\#use_hd\\#", "。");
        }
        contract = contract.replaceAll("\\#f_sxyd\\#",sargs);
        return contract;
    }



    public static String replace(String content) {
        if(StringUtils.isBlank(content)){
            return "";
        }
        content = "1、" + content;
        StringBuffer bs = new StringBuffer();
        int count = 1;
        for (int i = 0; i < content.length(); i++) {
            if (content.charAt(i) == ',') {
                count++;
                bs.append("<br /> " + count + "、");
            } else {
                bs.append(content.charAt(i));
            }
        }
        return bs.toString();
    }

    public static String replacewithSpan(String content){
        if(StringUtils.isBlank(content))
            return "";
        content = "<span class=\"underline\">1、"+content;
        StringBuffer bs = new StringBuffer();
        int count = 1;
        for(int i=0;i<content.length();i++){
            if(content.charAt(i) == '|'){
                count++;
                bs.append("</span><br /><span class=\"underline\">"+count+"、");
            }else{
                bs.append(content.charAt(i));
            }
        }

        bs.append("</span>");

       //  System.out.print(bs+"");System.out.print(bs.toString());
        return  bs.toString();
    }
//    public static void test(String html){
//        System.out.print(html.split(",")[0]);
//
//    }
    public static void main(String args[]){
        String cc = "1|1";
     //   System.out.print(cc.charAt(1)=='|');
        String html = "本合同甲方由委托代理人签订。若发生上述房屋产权纠纷或违约等事件均由委托代理人承担一切经济和法律责任。,本合同乙方由委托代理人签订。若发生上述房屋产权纠纷或违约等事件均由委托代理人承担一切经济和法律责任。,丙方收到甲方房产证#fcz_number#本.土地使用权证#td_number#本.不动产权证#bd_number#本.契证#qz_number#本。";
       System.out.print(DateUtils.getDate("yyyy"));

    }

    public static String getDicts(String contract_spacial, String importantClause) {
        if(StringUtils.isBlank(importantClause))
            return "";
        String []values = importantClause.split(",");
        String s = "";
        for(int i=0;i<values.length;i++){
            s =s + DictUtils.getDictLabel(contract_spacial,values[i],"")+"|";
        }

        s = s.substring(0,s.length()-1);
        return s;
    }
}
